#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

iter = 0
while True:
    with display_block('Entradas'):
        iter += 1
        a = rfraction(5)
        b = rfraction(5)
        c = rfraction(5)
        d = rfraction(5)
        yFunc = a * x + b
        Pto = (c, d)

    with display_block('Resultados'):
        correta = abs(a * c + b - d) / sqrt(1 + a * a)
        distOrigem = abs(b) / sqrt(1 + a * a)
        resps = [sqrt(2), correta, distOrigem]

        # Testa qualidade das respostas
        if distOrigem == correta:
            continue
        elif distOrigem * correta == 0:
            continue
        elif (not issimple(correta ** 2, 7)) or (not issimple(distOrigem ** 2, 7)):
            continue

        for frac in rfractions(force_pos=True, max_size=30):
            if len(resps) >= 8:
                break
            new = oneof(*resps) * frac
            if new not in resps:
                frac = (new.args[0] if type(new) is Mul else new)
                if issimple(frac, 5):
                    resps.append(new)

        try:
            distr1, distr2, distr3, distr4, distr5 = resps[3:]
            break
        except IndexError:
            continue
